<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">

      <el-form-item>
        <el-input
          v-model="dataFormQuery.jobName"
          clearable
          placeholder="请输入职位名称">
        </el-input>
      </el-form-item>

      <el-form-item>
        <!--<el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>-->
        <el-select v-model="dataFormQuery.isUrgency" clearable>
          <el-option value="0" label="非急聘"></el-option>
          <el-option value="1" label="急聘"></el-option>
        </el-select>

        <el-cascader
          clearable
          placeholder="请选择行业信息"
          v-model="dataForm.industryOptions"
          :options="industryOptions"
          @change="handleChangeIndustoryCondition">
        </el-cascader>

        <el-cascader
          clearable
          placeholder="请选择地址信息"
          v-model="dataForm.companyAddressOptions"
          :options="companyAddressOptions"
          @change="handleChangeAddressCondition">
        </el-cascader>
      </el-form-item>

      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button v-if="isAuth('workjobs:workjob:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
        <el-button v-if="isAuth('workjobs:workjob:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>

      <el-table-column
        prop="jobName"
        header-align="center"
        align="center"
        width="180"
        label="职位名称">
      </el-table-column>

      <el-table-column
        prop="jobDeptement"
        header-align="center"
        align="center"
        label="职位部门">
      </el-table-column>

      <el-table-column
        prop="jobDescript"
        header-align="center"
        align="center"
        label="职位描述">
      </el-table-column>

      <el-table-column
        prop="isUrgency"
        header-align="center"
        align="center"
        width="90"
        label="紧急招聘">
        <template slot-scope="scope">
          <el-tag type="danger" v-if="scope.row.isUrgency == 1">急</el-tag>
          <el-tag v-else type="success">正常</el-tag>
        </template>
      </el-table-column>


      <el-table-column
        prop="jobIssueStatus"
        header-align="center"
        align="center"
        width="100"
        label="发布状态">
        <template slot-scope="scope">
          <el-tag type="warning" v-if="scope.row.jobIssueStatus == 12010">发布中</el-tag>
          <el-tag v-else-if="scope.row.jobIssueStatus == 10220" type="danger">未发布</el-tag>
          <el-tag v-else-if="scope.row.jobIssueStatus == 10230" type="success">已发布</el-tag>
        </template>
      </el-table-column>



      <el-table-column
        prop="jobApproveStatus"
        header-align="center"
        align="center"
        width="100"
        label="职位审核">
        <template slot-scope="scope">
          <el-tag type="warning" v-if="scope.row.jobApproveStatus == 10130">审核中</el-tag>
          <el-tag v-else-if="scope.row.jobApproveStatus == 10110" type="success">已审核</el-tag>
          <el-tag v-else-if="scope.row.jobApproveStatus == 10120" type="danger">未审核</el-tag>
        </template>
      </el-table-column>

      <el-table-column
        prop="jobIsPass"
        header-align="center"
        align="center"
        label="职位申请"
        width="100"
      >
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.jobIsPass == 1">通过</el-tag>
          <el-tag v-else type="danger">不通过</el-tag>
        </template>
      </el-table-column>

      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="350"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="positionPublish(scope.row)">职位发布</el-button>
          <el-button type="text" size="small" @click="showJobInfo(scope.row)">详情</el-button>
          <el-button type="text" size="small" @click="approveJobInfo(scope.row,1)">审核通过</el-button>
          <el-button type="text" size="small" @click="approveJobInfo(scope.row,0)">审核不通过</el-button>
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
          <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>


    <el-dialog
      title="职位详情"
      :close-on-click-modal="false"
      :visible.sync="visible">
      <el-form :model="dataForm"
               label-width="130px"
               :inline="true"
      >
        <el-form-item label="职位名称" prop="jobName">
          <el-col :span="24">
            <el-input disabled v-model="dataForm.jobName" placeholder="职位名称"></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="职位部门" prop="jobDeptement">
          <el-input  disabled v-model="dataForm.jobDeptement" placeholder="职位部门"></el-input>
        </el-form-item>
        <el-form-item label="联系人" prop="jobContact">
          <el-input disabled v-model="dataForm.jobContact" placeholder="联系人"></el-input>
        </el-form-item>
        <el-form-item label="联系手机" prop="jobPhone">
          <el-input disabled v-model="dataForm.jobPhone" placeholder="联系手机"></el-input>
        </el-form-item>
        <el-form-item label="联系固话" prop="jobFixPhone">
          <el-input disabled v-model="dataForm.jobFixPhone" placeholder="联系固话"></el-input>
        </el-form-item>
        <el-form-item label="联系微信" prop="jobWechat">
          <el-input disabled v-model="dataForm.jobWechat" placeholder="联系微信"></el-input>
        </el-form-item>
        <el-form-item label="联系邮箱" prop="jobEmail">
          <el-input disabled v-model="dataForm.jobEmail" placeholder="联系邮箱"></el-input>
        </el-form-item>
        <el-form-item label="联系qq" prop="jobQq">
          <el-input disabled v-model="dataForm.jobQq" placeholder="联系qq"></el-input>
        </el-form-item>


        <el-form-item label="紧急招聘" prop="isUrgency">
          <el-col :span="22">
            <el-select disabled v-model="dataForm.isUrgency" placeholder="是否急聘">
              <el-option label="急聘" value="1"></el-option>
              <el-option label="非急聘" value="0"></el-option>
            </el-select>
          </el-col>
        </el-form-item>

        <el-form-item label="所属行业" prop="industryOptions" label-width="115px">
          <el-col :span="22">
            <el-cascader
              disabled
              v-model="industryOptionsArr"
              :options="industryOptions"
              >
            </el-cascader>
          </el-col>
        </el-form-item>

        <el-form-item label="工作地址" property="companyAddressOptions">
          <el-col :span="22">
            <el-cascader
              disabled
              v-model="companyAddressOptionsArr"
              :options="companyAddressOptions"
              >
            </el-cascader>
          </el-col>
        </el-form-item>

        <el-form-item label="详细地址" prop="jobDetailAddress" label-width="115px">
          <el-col :span="24">
            <el-input disabled v-model="dataForm.jobDetailAddress" placeholder="详细地址"></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="薪资范围" required>
          <el-col :span="11">
            <el-form-item prop="jobSalaryStart">
              <el-input disabled v-model="dataForm.jobSalaryStart" style="width: 100%;" placeholder="薪资范围"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="1">-</el-col>
          <el-col :span="11">
            <el-form-item prop="jobSalaryEnd">
              <el-input disabled v-model="dataForm.jobSalaryEnd" style="width: 100%;" placeholder="薪资范围"></el-input>
            </el-form-item>
          </el-col>
        </el-form-item>

        <el-form-item label="年龄要求" required>
          <el-col :span="11">
            <el-form-item prop="jobAgeStart">
              <el-input disabled v-model="dataForm.jobAgeStart" style="width: 100%;" placeholder="年龄要求"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="1">-</el-col>
          <el-col :span="11">
            <el-form-item prop="jobAgeEnd">
              <el-input disabled v-model="dataForm.jobAgeEnd" style="width: 100%;" placeholder="年龄要求"></el-input>
            </el-form-item>
          </el-col>
        </el-form-item>


        <el-form-item label="证书要求" prop="detailPosition" >
          <el-select
            disabled
            v-model="positionCertifiCate"
            clearable
            multiple
            placeholder="请选择">
            <el-option
              v-for="item in certifiCateOption"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="职位福利" prop="detailPosition" label-width="100px">
          <el-select
            disabled
            v-model="positionWalfare"
            clearable
            multiple
            placeholder="请选择">
            <el-option
              v-for="item in walfareOption"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>


        <el-form-item label="职位描述" prop="jobDescript">
          <el-input
            disabled
            style="width: 500px"
            type="textarea"
            v-model="dataForm.jobDescript"
            placeholder="职位描述"
            :rows = "5"
            :cols="50"
            maxlength="100"
            show-word-limit>
          </el-input>
        </el-form-item>

      </el-form>
      <span slot="footer" class="dialog-footer">
      <el-button @click="closeDialog()">取消</el-button>
    </span>
    </el-dialog>



    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import AddOrUpdate from './workjob-add-or-update'

  export default {
    inject:['reload'],
    data () {
      return {
        visible:false,
        dataFormQuery: {
          jobName:undefined,

          isUrgency:undefined,

          tradeId: undefined,
          classifyId: undefined,
          jobTypeId: undefined,

          provincesId: undefined,
          citysId: undefined,
          areasId: undefined,
        },

        dataForm: {
          key: '',
          companyAddressOptionsArr:[],
          jobName: '',
          jobDescript: '',
          jobDeptement: '',
          jobContact: '',
          jobPhone: '',
          jobFixPhone: '',
          jobWechat: '',
          jobEmail: '',
          jobQq: '',
          isUrgency: '',                     //是否是急聘
          companyId: '',
          tradeId: '',
          classifyId: '',
          jobTypeId: '',
          provincesId: '',
          citysId: '',
          areasId: '',
          jobSalaryStart: '',
          jobSalaryEnd: '',
          jobApproveStatus: '',
          jobIssueStatus: '',
          jobRecruitStatus: '',
          jobIsPass: '',
          jobAgeStart: '',
          jobAgeEnd: '',
          jobDetailAddress: '',
        },
        userId:'',                        //当前的userId
        certifiCateOption:[],             //证书列表
        walfareOption:[],                 //福利列表


        positionCertifiCate:[],
        positionWalfare:[],

        industryOptions:[],               //行业的选项卡
        industryOptionsArr:[],            //选中的值
        //1000 1001 100101
        companyAddressOptions:[],         //地址的选项卡
        companyAddressOptionsArr:[],         //选中的值
        //"110000","110100","110101"



        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
      AddOrUpdate
    },
    activated () {
      this.getDataList()
    },
    mounted () {
      this.getUserInfo()
      this.loadingIndustory()
      this.loadingCompanyAddress()
      this.loadingCertifiCate()
      this.loadingWalfare()


    },
    methods: {
      //职位发布方法
      positionPublish(jobObj){
        console.log(" ----->> ",jobObj)
        this.$http({
          url: this.$http.adornUrl('/workjobs/workjob/publish/'   +jobObj.id),
          method: 'post',
        })
        .then(data => {
          if (data && data.data.code === 0){
            this.$message({
              type:'success',
              message:'职位发布成功'
            })
            this.reload()
          }
        }).catch(err => {
          Promise.reject(err)
        })
      },
      //职位审核方法
      approveJobInfo(jobObj,ispass){
        this.$http({
          url: this.$http.adornUrl('/workjobs/workjob/approve/' + jobObj.id +'/' + ispass),
          method: 'post',
        }).then(data =>{
          if (data.data.code === 0){
            this.$message({
              type:'success',
              message:'审批成功'
            })
            this.reload()
          }else if (data.data.code === 500){
            this.$message({
              type:'warning',
              message:data.data.msg
            })
          }
        })
      },
      //显示工作职位的相关信息
      showJobInfo(jobObj){
        //this.dataForm.isUrgency = jobObj.isUrgency.toString()
        this.$http({
          url: this.$http.adornUrl('/workjobs/workjob/jobInfo/' + jobObj.id),
          method: 'get',
        }).then(data =>{
          if (data.data.code === 0){
            debugger
            console.log("data detail==>> ",data)
            let arrayDataObj = data.data.data
            arrayDataObj.isUrgency = arrayDataObj.isUrgency.toString()
            this.dataForm = arrayDataObj
          }
        })

        this.$http({
          url:this.$http.adornUrl('/workjobs/workjob/address-option/' + jobObj.id),
          method:'get'
        })
        .then(data => {
          if (data && data.data.code === 0){
            this.companyAddressOptionsArr = data.data.data
          }
        })

        this.$http({
          url:this.$http.adornUrl('/workjobs/workjob/industory-option/' + jobObj.id),
          method:'get'
        })
          .then(data => {
            if (data && data.data.code === 0){
              this.industryOptionsArr = data.data.data
            }
          })

        this.$http({
          url:this.$http.adornUrl('/workjobs/workjob/certificates-option/' + jobObj.id),
          method:'get'
        })
          .then(data => {
            if (data && data.data.code === 0){
              this.positionCertifiCate = data.data.data
            }
          })

        this.$http({
          url:this.$http.adornUrl('/workjobs/workjob/walfare-option/' + jobObj.id),
          method:'get'
        })
          .then(data => {
            if (data && data.data.code === 0){
              this.positionWalfare = data.data.data
            }
          })




        this.visible = true
      },
      /*关闭弹窗*/
      closeDialog(){
        this.visible = false
        this.reload()
      },



      /*加载已经登录的用户*/
      getUserInfo () {
        this.$http({
          url: this.$http.adornUrl('/sys/user/info'),
          method: 'get',
          params: this.$http.adornParams()
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.loading = false
            this.userId = data.user.userId
          }
        })
      },
      //加载行业选项
      loadingIndustory(){
        this.$http({
          url: this.$http.adornUrl('/workjobs/workjob/tree-option-ccj'),
          method: 'get',
        }).then(({data}) => {
          if (data && data.code === 0){
            this.industryOptions = data.data
          }
        })
      },
      //加载企业地址选项
      loadingCompanyAddress(){
        this.$http({
          url: this.$http.adornUrl('/companys/company/tree-option-pcr'),
          method: 'get',
        }).then(({data}) => {
          if (data && data.code === 0){
            this.companyAddressOptions = data.data
          }
        })
      },
      //加载证书列表
      loadingCertifiCate(){
        this.$http({
          url: this.$http.adornUrl('/common/certificate/select-option'),
          method: 'get',
        }).then(({data}) => {
          if (data && data.code === 0){
            this.certifiCateOption = data.data
          }
        })
      },
      //加载福利列表
      loadingWalfare(){
        this.$http({
          url: this.$http.adornUrl('/common/welfare/select-option'),
          method: 'get',
        }).then(({data}) => {
          if (data && data.code === 0){
            this.walfareOption = data.data
          }
        })
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/workjobs/workjob/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'key': this.dataForm.key,
            'queryCondition':this.dataFormQuery
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/workjobs/workjob/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },



      //行业信息
      handleChangeIndustoryCondition(value){
        console.log("vlaue indeutory====>",value  )
        this.dataFormQuery.tradeId = value[0]
        this.dataFormQuery.classifyId = value[1]
        this.dataFormQuery.jobTypeId = value[2]
      },

      //地址信息
      handleChangeAddressCondition(value){
        console.log("vlaue Address====>",value  )
        this.dataFormQuery.provincesId = value[0]
        this.dataFormQuery.cityesId = value[1]
        this.dataFormQuery.areasId = value[2]
      }
    }
  }
</script>
